<?php 

require_once ($DOCUMENT_ROOT . '/includes/functions.php');

do_header ('Registration Form', '');

	if ($submit)
    {
    	// create random password
    	// just a random number and crypt it - should be sufficient
    	$pass = rand ();
    	$pass = crypt ($pass, 'password');
    	
    	// create user in db and set pass
    	if (db_connect ())
    	{
    		register ($email, $pass);
    		
    		$s = "bobcat password";
    		$m = "your login name: $email\nyour password: $pass\nwe realize the password is long, but just cut and paste it, then change it once you log in.
 log in at http://bobcat.hungrychild.org\nthe bobcat team\nadmin@bobcat.hungrychild.org\n";
	    	
			mail ($email, $s, $m, "From: accounts@bobcat.hungrychild.org\r\n");
			
			echo "<p>an email containing your password has been sent to the email address you provided.</p>".
			"<p>remember that your email address will be your username</p>".
			"<p>thank you for signing up. Enjoy!</p>";
			do_url ('/', 'Return to homepage');
    	}
    	else
    	{
    		report_error ($PHP_SELF, mysql_error (), "db connection failure", '0');
    	}
    }
    else
    {
?>
<a href="/"><img id="logo" src="/images/logo.png" alt="bobcat - professor rating system" /></a>
<h1>Register:</h1>
<ul id="box"><li>Please enter a valid email address as your initial password will be sent there.</li>
<li>you will be given a chance later to change the password if you see fit.</li>
<li>your email will be your username</li></ul>

<form method="post" action="<?php echo $PHP_SELF; ?>">
<p>Email address:<br />
 <input type="text" name="email" size="30" /></p>
<p>Select your school from the list:<br />
  <select name="select">
    <option value="montana.edu" selected="selected">Montana State University</option>
  </select> 
  </p>
<p><input type="submit" value="Sign Up" name="submit" />
</p>
</form>

<?php
    }
do_footer ();
?>
